/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interface;

import java.awt.Color;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Guilherme
 */
public class Resposta extends javax.swing.JFrame {

    /**
     * Creates new form Resposta
     */
    public Resposta() {
        resultado = Base.Perguntas.getAcertou();        
        initComponents();
        lblPosicao.setText(Base.Perguntas.qtdeResp());
        repaintBotao();        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlResposta = new javax.swing.JPanel();
        lblPosicao = new javax.swing.JLabel();
        lblVoltar = new javax.swing.JLabel();
        lblAvancar = new javax.swing.JLabel();
        btnStatus = new javax.swing.JButton();
        lblResposta = new javax.swing.JLabel();
        lblAlternativa = new javax.swing.JLabel();
        lblAlt = new javax.swing.JLabel();
        lblLink = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Quiz Responda e Aprenda");

        pnlResposta.setBackground(new java.awt.Color(253, 199, 111));
        pnlResposta.setPreferredSize(new java.awt.Dimension(920, 583));
        pnlResposta.setLayout(null);

        lblPosicao.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblPosicao.setText("1/10");
        pnlResposta.add(lblPosicao);
        lblPosicao.setBounds(840, 20, 50, 17);

        lblVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/ant2.png"))); // NOI18N
        lblVoltar.setToolTipText("Voltar");
        lblVoltar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        lblVoltar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblVoltarMouseClicked(evt);
            }
        });
        pnlResposta.add(lblVoltar);
        lblVoltar.setBounds(720, 490, 80, 50);

        lblAvancar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/prox2.png"))); // NOI18N
        lblAvancar.setToolTipText("Avançar");
        lblAvancar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        lblAvancar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblAvancarMouseClicked(evt);
            }
        });
        pnlResposta.add(lblAvancar);
        lblAvancar.setBounds(810, 490, 80, 50);

        btnStatus.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
        btnStatus.setForeground(new java.awt.Color(51, 204, 0));
        btnStatus.setText("CORRETO !");
        btnStatus.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        pnlResposta.add(btnStatus);
        btnStatus.setBounds(240, 20, 400, 70);

        lblResposta.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblResposta.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        lblResposta.setAlignmentX(0.5F);
        lblResposta.setAutoscrolls(true);
        pnlResposta.add(lblResposta);
        lblResposta.setBounds(80, 150, 730, 310);

        lblAlternativa.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblAlternativa.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblAlternativa.setText("Alternativa correta:");
        pnlResposta.add(lblAlternativa);
        lblAlternativa.setBounds(40, 110, 180, 20);
        lblAlternativa.setVisible(false);

        lblAlt.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        pnlResposta.add(lblAlt);
        lblAlt.setBounds(230, 110, 30, 20);

        lblLink.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblLink.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        lblLink.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblLinkMouseClicked(evt);
            }
        });
        pnlResposta.add(lblLink);
        lblLink.setBounds(90, 500, 190, 30);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 909, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(pnlResposta, javax.swing.GroupLayout.DEFAULT_SIZE, 909, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 583, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(pnlResposta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-925)/2, (screenSize.height-616)/2, 925, 616);
    }// </editor-fold>//GEN-END:initComponents

    private void repaintBotao(){
        if(!resultado){
            btnStatus.setText("ERRADO!");
            btnStatus.setForeground(new java.awt.Color(255,0,0));  
            lblAlternativa.setVisible(true);           
            lblAlt.setVisible(true);
            lblAlt.setText(Base.Perguntas.correta());
        }
        lblResposta.setText(Base.Perguntas.resposta());
        lblLink.setText(Base.Perguntas.getLink());
    }
    private void lblAvancarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblAvancarMouseClicked
        Base.Perguntas.apresentar=false;
        Base.Perguntas.voltar=false;
        if(Base.Perguntas.terminou()){
            Final f = new Final();
            f.setVisible(true);
            f.setExtendedState(NORMAL);
            f.toFront();
            f.requestFocus();
            this.setVisible(false);
        }else{
            Pergunta p = new Pergunta(); 
            p.setExtendedState(NORMAL);
            p.toFront();
            p.requestFocus();
            this.setVisible(false);
            p.setVisible(true);            
        }
    }//GEN-LAST:event_lblAvancarMouseClicked

    private void lblLinkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblLinkMouseClicked
        try {
            URI uri = new URI(Base.Perguntas.link());
            if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().browse(uri);
            } catch (IOException e) { /* TODO: error handling */ }
        } else { /* TODO: error handling */ }
        } catch (URISyntaxException ex) {
            Logger.getLogger(Resposta.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_lblLinkMouseClicked

    private void lblVoltarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblVoltarMouseClicked
        //deve apresentar aúltima pergunta com as respostas do sujeito...
        Base.Perguntas.apresentar= true;
        Pergunta p = new Pergunta();
        p.setExtendedState(NORMAL);
        p.toFront();
        p.requestFocus();
        this.setVisible(false);
        p.setVisible(true);        
    }//GEN-LAST:event_lblVoltarMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Resposta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Resposta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Resposta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Resposta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Resposta().setVisible(true);
            }
        });
    }
    
    private boolean resultado;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnStatus;
    private javax.swing.JLabel lblAlt;
    private javax.swing.JLabel lblAlternativa;
    private javax.swing.JLabel lblAvancar;
    private javax.swing.JLabel lblLink;
    private javax.swing.JLabel lblPosicao;
    private javax.swing.JLabel lblResposta;
    private javax.swing.JLabel lblVoltar;
    private javax.swing.JPanel pnlResposta;
    // End of variables declaration//GEN-END:variables
}
